package zack.gateway.core.bind;

import zack.gateway.core.session.GatewaySession;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Map;

/**映射代理
 * @author A1793
 */
public class MapperProxy implements MethodInterceptor {

    private GatewaySession session;
    private String uri;

    public MapperProxy(String uri, GatewaySession session) {
        this.uri = uri;
        this.session = session;
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        MapperMethod mapperMethod = new MapperMethod(uri, method, session.getConfiguration());
        return mapperMethod.execute(session,(Map<String,Object>) objects[0]);
    }
}
